<template>
    <div class="register">
        <div class="title clearfix">
            <div class="logo fl">
                <Logo></Logo>
            </div>
            <div class="name fl">极客商城</div>
            <div class="name fl">欢迎注册</div>
        </div>
        <div class="register-info">
            <div class="register-content">
                <div class="register-text">
                    <div class="register-name">开始注册</div>
                    <div class="register-username">
                        <label for="username">
                            <img
                                src="@/assets/images/login/username.png"
                                alt=""
                            />
                        </label>
                        <input
                            type="text"
                            id="username"
                            placeholder="请输入用户名"
                            v-model="registerInfo.username"
                        />
                    </div>
                    <div class="register-mobile">
                        <label for="mobile">
                            <img
                                src="@/assets/images/login/username.png"
                                alt=""
                            />
                        </label>
                        <input
                            type="text"
                            id="username"
                            placeholder="请输入电话号码(用于登录)"
                            v-model="registerInfo.mobile"
                        />
                    </div>
                    <div class="register-password">
                        <label for="password">
                            <img
                                src="@/assets/images/login/password.png"
                                alt=""
                            />
                        </label>
                        <input
                            type="password"
                            id="password"
                            placeholder="请输入密码"
                            v-model="registerInfo.password"
                        />
                    </div>
                    <button class="register-commit" @click="register">
                        立即注册
                    </button>
                    <div class="reg">
                        <a href="/login">已有账号, 返回登录</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>


<script setup>
import Logo from "@/components/common/Logo.vue";
import { registerRequest } from "@/network/user.js";
import { useStore } from "vuex";
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();

const store = useStore()
let registerInfo = reactive({
    username: "",
    mobile: "",
    password: "",
})


const register = () => {
    console.log(registerInfo)
    registerRequest(registerInfo).then(res => {
        console.log(res);
        if (res.status == 4000) {
            alert("注册成功");
            window.localStorage.setItem("token", res.data.token);
            window.localStorage.setItem("username", res.data.username);
            store.commit("setIsLogin", true);
            store.commit("setIsUserName", res.data.username);
            router.push("/login");
        } else {
            alert(res.data);
            // alert("注册成功");
            router.push("/login");
        }

    })
}

</script>



<style lang="less" scoped>
.register {
    background-image: url("@/assets/images/login/login.jpg");
    width: 100%;
    height: 100%;
    position: fixed;
    background-size: 100% 100%;
    .title {
        width: 1000px;
        margin: 0 auto;
        height: 80px;
        line-height: 80px;
        .logo {
            height: 40px;
        }
        .name {
            font-size: 30px;
            margin-left: 10px;
            vertical-align: middle;
            margin-top: 30px;
        }
    }
    .register-info {
        .register-content {
            width: 990px;
            height: 475px;
            // margin: 80px auto;
            margin-top: 60px;
            margin-left: 500px;
            .register-text {
                margin-top: 20px;
                width: 500px;
                height: 470px;
                background-color: #fff;
                // float: right;
                border-radius: 25px;
                .register-name {
                    width: 500px;
                    border-radius: 25px;
                    height: 40px;
                    line-height: 40px;
                    text-align: center;
                    color: #e93854;
                    font-size: 24px;
                    font-weight: 700;
                    border-bottom: 1px solid #f4f4f4;
                }
                .register-username,
                .register-mobile,
                .register-password {
                    border: 1px solid #bdbdbd;
                    // border-radius: 25px;
                    width: 440px;
                    height: 50px;
                    margin: 30px auto 0;
                    line-height: 50px;
                    label {
                        display: inline-block;
                        background-color: #f4f4f4;
                        width: 50px;
                        // height: 50px;
                        text-align: center;
                        line-height: 50px;
                        border-right: 1px solid #bdbdbd;
                        img {
                            width: 30px;
                            height: 30px;
                        }
                    }
                    input {
                        padding-left: 30px;
                        font-size: 16px;
                        line-height: 50px;
                    }
                }
                .register-commit {
                    width: 440px;
                    height: 55px;
                    background-color: #e93854;
                    color: white;
                    margin-top: 20px;
                    font-size: 20px;
                    margin-left: 30px;
                }
                .reg {
                    margin-top: 50px;
                    font-weight: 700;
                    background-color: #fcfcfc;
                    height: 50px;
                    width: 500px;
                    line-height: 50px;
                    text-align: right;
                    border-radius: 25px;
                    a {
                        color: #e93854;
                        margin-right: 60px;
                        // text-align: right;
                        font-size: 16px;
                    }
                }
            }
        }
    }
}
</style>